/*
 * #%L
 * java model
 * %%
 * Copyright (C) 2009 - 2011 prefabware.com Stefan Isele
 * %%
 * All Rights Reserved.
 * This program is dual-licensed under the GNU General Public license
 * or a commercial license.
 * You may select to use one or the other of these licenses.
 * To obtain a commercial license please contact Stefan Isele at www.stefan-isele.de
 * Any modifications to this file must keep this entire header intact.
 * Redistribution, except as permitted by the selected license, is prohibited.
 * #L%
 */
package com.prefabware.jmodel.code;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.prefabware.commons.CollectionUtil;

public class JBlock implements JCodable {
	private List<JCodable> codables;

	public JBlock() {
		super();
		this.codables = new ArrayList<JCodable>();
	}

	public JBlock add(JCodable e) {
		codables.add(e);
		return this;
	}

	public boolean addAll(Collection<? extends JCodable> c) {
		return codables.addAll(c);
	}

	public List<JCodable> getCodables() {
		return codables;
	}

	@Override
	public String asCode(JCodeOptions options) {
		// all codables, each terminated by ;
		List<String> list = JCodables.getAsCode(this.codables,options);
		// all lines are seperated by semicolon and line feed
		String terminatedBy = CollectionUtil.seperatedBy(list, ";\n");
		// only the last one gets no line feed
		return terminatedBy+";";
	}
}
